/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.text.MessageFormat;
import java.text.ParsePosition;

/**
 *
 * @author WangShuai
 */
public class MessageFormatTest {

    public static void main(String[] args) {
        //System.out.println(MessageFormat.format("Hello,{0}", "Tom"));   // No Subformat Created
        System.out.println(MessageFormat.format("This is {0,number}", 123456));  //NumberFormat.getInstance(getLocale())    This is 123,456

        System.out.println(MessageFormat.format("This is {0,number,currency}", 123456));//NumberFormat.getCurrencyInstance(getLocale())

        System.out.println(MessageFormat.format("Hello,{0},'''{0}''", "Tom's cat", "AA"));  //单引号 '和 {为特殊字符，单引号为转义字符，使用{时要加转义字符  Hello,Tom's cat,'{0}'

        MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}");   //使用SubformatPattern
        Object[] objs = {new Double(3.1415)};  //使用Object数组作为参数，否则会出现ClassCastException
        String result = mf.format(objs);
        System.out.println(result);
    }
}
